package com.reflex.cglib;

import com.reflex.jvm.model.Person;
import net.sf.cglib.reflect.FastClass;
import net.sf.cglib.reflect.FastMethod;

import java.lang.reflect.InvocationTargetException;

public class CglibTest {

    /**
     * 据说 cglib 的反射 比 jvm 效率高
     * @param args
     */
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException {
        FastClass fastClass = FastClass.create(Person.class);
        Person person = (Person) fastClass.newInstance();
        FastMethod fastMethod = fastClass.getMethod("setName", new Class[]{String.class});
        fastMethod.invoke(person, new Object[]{"hello cglib"});
        System.out.println(person.getName());
    }
}
